package com.example.mywike.config.shiroConfig;


import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
/**
 * @Author xiyanqiulvgui
 * @Date 2020/9/6 21:58
 * @Description 配置shiro密码比较器
 * @Version 1.0.0
 */
@Slf4j
public class CredentialsMatcherMe extends SimpleCredentialsMatcher {

    /**
     * @param token 用户传入的信息
     * @param info 从数据库中获取的信息
     * @author xiyangqilvgui
     * @decription
     * @date 2020/9/12 23:15
     * @version 1.0.0
     * @return
     * */
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken userToken=(UsernamePasswordToken) token;
        //获得用户输入的密码:(可以采用加盐(salt)的方式去检验)
        String inPassword = new String(userToken.getPassword());
        //获得数据库中的密码
        String dbPassword=(String) info.getCredentials();
        //进行密码的比对

        System.out.println("inPassword = " + inPassword);
        System.out.println("dbPassword = " + dbPassword);
        log.info("inpassword -> {} , dbpassword -> {}",inPassword,dbPassword);

        return this.equals(inPassword, dbPassword);
    }
}